<template>
  <div class="float-menu" :class="!isFold ? 'mask' : ''" v-if="compData.show">
    <div class="float-menu-wrap" :class="compData.mode == 2 ? 'horizontal' : 'vertical'">
      <template v-if="!isFold">
        <div class="float-menu-item" v-for="item in compData.list" :key="item">
          <sa-image :url="item.src" size="26" :suffix="null" />
          <div v-if="compData.isText" class="text" :style="titleStyle(item.title)">
            {{ item.title.text }}
          </div>
        </div>
      </template>
      <div
        class="float-menu-button sa-flex sa-row-center"
        :class="!isFold ? 'fold' : ''"
        :style="buttonStyle"
        @click="isFold = !isFold"
      >
        <el-icon><CloseBold /></el-icon>
      </div>
    </div>
  </div>
</template>

<script setup>
  import { computed, ref } from 'vue';
  import { themeColor } from '../../../../data.js';

  const props = defineProps(['compData', 'allData']);

  const isFold = ref(false);

  const buttonStyle = computed(() => ({
    background: themeColor[props.allData.theme || 'orange'].color1,
  }));

  function titleStyle(title) {
    return {
      color: title.color || '#eee',
    };
  }
</script>

<style lang="scss" scoped>
  .float-menu {
    height: 100%;
    // position: relative;
    &.mask {
      background: rgb(153, 153, 153);
    }
    .float-menu-wrap {
      position: absolute;
      right: 30px;
      bottom: 50px;
      display: flex;
      align-items: center;
      justify-content: center;
      .float-menu-item {
        margin-right: 10px;
        margin-bottom: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
      }
      .text {
        line-height: 12px;
        font-size: 12px;
        margin-top: 4px;
      }
      .float-menu-button {
        width: 42px;
        height: 42px;
        font-size: 20px;
        border-radius: 50%;
        color: #fff;
        transition: all 0.3s linear;
        cursor: pointer;
        transform: rotateZ(135deg);
        -webkit-transform: rotateZ(135deg);
        &.fold {
          transform: rotateZ(0deg);
          -webkit-transform: rotateZ(0deg);
        }
      }
      &.vertical {
        flex-direction: column;
        .float-menu-item {
          margin-right: 0;
          margin-bottom: 10px;
        }
      }
    }
  }
</style>
